//
//  TicTacController.h
//  TicTacToe
//
//  Created by Tim on 09-11-23.
//  Copyright 2009 Tim Dimsdale. All rights reserved.
//
// This file is part of TicTacToe.
// 
// TicTacToe is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// TicTacToe is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with TicTacToe.  If not, see <http://www.gnu.org/licenses/>
//
#import <Cocoa/Cocoa.h>

#import "TicTacOpponent.h"
#import "TicTacModel.h"
#import "TicTacView.h"
#import <QTKit/QTKit.h>
#import "TicTacNotifications.h"
#import "TicTacPosition.h"

/*!
 \brief TicTacController is the main controller in the MVC pattern for the tic tac toe game.
 
 It is expected that the controller is setup in the xib to be an instance on application startup.
 */
@interface TicTacController : NSController {
	/*!
	 Reference to the tic tac view.  It is expected that this is connected to the view in the xib.
	 */
	IBOutlet TicTacView* myView;

	/*!
	 The data model to be manipulated.  This is owned by the controller.
	 */
	TicTacModel* myModel;
	
	/*!
	 A slider indicating the current computer skill.
	 TODO: this should really just be a level, not a sliderCell, but I couldn't figure out how to connect just an int over to the intValue of the slider properly.
	 */
	IBOutlet NSSliderCell* currentComputerSkill;
	/*!
	 The computer opponent.  This is owned by the controller.
	 */
	TicTacOpponent *opponent;
	/*!
	 Whether or not anybody is allowed to move.
	 */
	bool allowMoves;

	/*!
	 The player code for the human player, could be TICTAC_X, or TICTAC_O
	 */
	int	humanPlayer;
	/*!
	 The player code for the computer player, could be TICTAC_X, or TICTAC_O
	 */
	int computerPlayer;	

	
}

/*!
 \brief Starts a new game, clears the existing model, refreshes the screen, and enables the grid.
 \param pId not used.  This is here to enable connections in the xib.
 */
- (IBAction)newGame:(id)pId; 

/*!
 \brief Call this to commit the current computer skill level.
 \todo this should be revisisted to figure out how to propery hook up an NSSlider without having a reference in the controller.
 \param pId not used.  This is here to enable connections in the xib.
 */
- (IBAction)changeComputerSkillLevel:(id)pId; 

/*!
 \brief Call this with the desired human position for proper gameplay.  
 \param humanDesiredPosition the position the human wants.
 In reality this is connected to 
 */
- (void)takeTurns:(TicTacPosition* ) humanDesiredPosition;

/*!
 \brief Internal.  Use takeTurns for proper workflow.
 \param humanDesiredPosition the position for the human.
*/
- (bool)humanTakeTurn:(TicTacPosition *)humanDesiredPosition;

/*!
 \brief Internal.  Use takeTurns for proper workflow.
 Computer's turn.
 */
- (void)computerTakeTurn;

/*!
 \brief Retrives the model used by the controller
 \returns the data model.
 */
- (TicTacModel*)getModel;

//-(void) tictacViewLoadedNotificationHandler:(NSNotification *)notification;
/*!
 \brief Handles the HumanPerformedEventNotification event.
 \param notification The object property in the notification should be a TicTacPosition*
 Leverages the cocoa message center with NSNotificationCenter.
 This will invoke takeTurns.
 */
- (void)humanEventNotificationHandler:(NSNotification *)notification;

@end
